<style lang="less" scoped>
.pageview {
    height: 100%;
    background-color: #f1f1f1;
    overflow-y: auto;
    padding-bottom: 80px;
    box-sizing: border-box;
    .comphead {
        position: fixed;
        width: 100%;
        height: 0.44rem;
        top: 0;
        left: 0;
        z-index: 3000;
    }
}
</style>
<template>
    <div class="pageview workbench">
        <CompHead class="comphead" />
        <CompFlodbox :fdata="data" />
        <CompFlodbox2 :fdata="data2" />
        <CompFlodbox3 :fdata="data3" />
        <CompFlodbox4 :fdata="data4" />
        <CompFooter @onReject="clickShowModel" @onResovle="onResovle" />
        <ModelReject v-model="showModel" @onOk="onOk" />
    </div>
</template>
<script>
import CompHead from "./comp/head";
import CompFooter from "./comp/foooter";
import CompFlodbox from "./comp/foldbox";
import CompFlodbox2 from "./comp/foldbox2";
import CompFlodbox3 from "./comp/foldbox3";
import CompFlodbox4 from "./comp/foldbox4";
import ModelReject from "@/components/modelReject";

import {
    getContractInfo,
    getTenantInfo,
    getShopInfo,
    getRents,
    contractAudit
} from "@/api";

export default {
    data() {
        return {
            showModel: false,
            data: {},
            data2: {},
            data3: [],
            data4: {}
        };
    },
    components: {
        CompHead,
        CompFooter,
        CompFlodbox,
        CompFlodbox2,
        CompFlodbox3,
        CompFlodbox4,
        ModelReject
    },
    methods: {
        // 基本信息
        getContractInfo() {
            var query = this.$route.query || {};
            getContractInfo({
                contract_content_id: query.id
            }).then(res => {
                if (res.code == 1) {
                    var data = res.data;
                    this.data = data;

                    var shopids = [];
                    data.shop_info.forEach(row => {
                        shopids.push(row.id);
                    });
                    this.getShopInfo(shopids);
                }
            });
        },

        // 承租商信息（乙方）
        getTenantInfo() {
            var query = this.$route.query || {};
            getTenantInfo({
                second_party_id: query.sid
            }).then(res => {
                if (res.code == 1) {
                    this.data2 = res.data;
                }
            });
        },

        // 商铺信息
        getShopInfo(ids) {
            var prs = [];
            ids.forEach(id => {
                prs.push(
                    getShopInfo({
                        id: id
                    })
                );
            });

            Promise.all(prs).then(res => {
                console.log(res);
                var arr = [];
                res.forEach(row => {
                    if (row.code == 1) {
                        arr.push(row.data);
                    }
                });
                this.data3 = arr;
            });
        },

        // 获取合约租金信息
        getRents() {
            var query = this.$route.query || {};
            getRents({
                contract_content_id: query.id
            }).then(res => {
                if (res.code == 1) {
                    var data = res.data;
                    this.data4 = data;
                }
            });
        },

        // 点击驳回 需要弹窗写理由
        clickShowModel() {
            this.showModel = true;
        },

        // 确认驳回
        onOk(msg) {
            var query = this.$route.query || {};
            var data = {
                contract_content_id: query.id,
                operation: 2,
                reject_reason: msg
            };
            contractAudit(data).then(res => {
                if (res.code == 1) {
                    this.$toast(res.msg);
                    setTimeout(() => {
                        this.$router.back(-1);
                    }, 500);
                } else {
                    this.$toast(res.msg);
                }
            });
        },

        // 点击确定
        onResovle() {
            var query = this.$route.query || {};
            var data = {
                contract_content_id: query.id,
                operation: 1,
                reject_reason: ""
            };
            contractAudit(data).then(res => {
                if (res.code == 1) {
                    this.$toast(res.msg);
                    setTimeout(() => {
                        this.$router.back(-1);
                    }, 500);
                } else {
                    this.$toast(res.msg);
                }
            });
        }
    },
    mounted() {
        this.getContractInfo();
        this.getTenantInfo();
        this.getRents();
    }
};
</script>
